import VueRouter from "vue-router";

import Home from '@/views/Home.vue'
import Furnace from "@/views/bigscreen/furnace.vue";
import Three from "@/views/bigscreen/three.vue";
import Slab from "@/views/stat/slab.vue";
import Redis from "@/views/stat/redis.vue";
import Redis2 from "@/views/stat/redis2.vue";
import cool from "@/views/stat/cool.vue";
import login from "@/views/stat/login.vue";
import { Message } from 'element-ui';
import point from '@/views/point/index.vue'
import point2 from '@/views/point/point.vue'
import EditPoint from "@/views/point/EditPoint.vue";
import Furnace2 from "@/views/bigscreen/furnace2.vue";

var router = new VueRouter({
    routes:[
        {
            path: '/',
            component: Home
        },
        {
            path: '/furnace',
            component: Furnace
        },
        {
            path: '/furnace2',
            component: Furnace2
        },
        {
            path: '/three',
            component: Three
        },
        {
            path: '/test',
            component: Three
        },
        {
            path: '/slab',
            component: Slab
        },
        {
            path: '/redis',
            component: Redis
        },{
            path: '/redis2',
            meta: {isAuth: true},
            component: Redis2
        },
        {
            path: '/cool',
            component: cool
        },
        {
            path: '/login',
            component: login
        },
        {
            path: '/point',
            component: point
        },
        {
            path: '/point2',
            component: point2,
            meta: {
                title: '点位管理',
            }
        },
        {
            path: '/edit',
            component: EditPoint
        },
        {
            path: '/energyshare',
            component: () => import('@/views/point/EnergyShare.vue')
        },
        {
            path: '/calcRule',
            component: () => import('@/views/point/CalcRule.vue')
        },
        {
            path: '/linkTracing',
            component: () => import('@/views/system/index2.vue')
        }


    ]
})

//全局前置守卫：初始化时执行、每次路由切换前执行
router.beforeEach((to,from,next)=>{
    document.title = to.meta.title ? '加热炉程序后台系统 | ' + to.meta.title : '加热炉后台程序系统';

    if(to.meta.isAuth){ //判断当前路由是否需要进行权限控制
        if(localStorage.getItem('login-status') === 'success'){ //权限控制的具体规则
            next() //放行
        }else{
            Message.error('请先进行Redis客户端连接')
            next({path:'login'})
        }
    }else{
        next() //放行
    }
})

export default router;